package dangs.controller;

import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import dangs.dao.PayMethodDAO;
import dangs.vo.PayMethodVO;

public class PayMethodController extends MultiActionController {
	private PayMethodDAO pmDAO;
	private PayMethodVO pmvo;

	public PayMethodController(){}
	public void setPayMethodDAO(PayMethodDAO pmDAO) {
		this.pmDAO = pmDAO;
	}
	
	
	public ModelAndView payMethodRegisterForm(HttpServletRequest request, HttpServletResponse response) throws Exception{
		 return new ModelAndView("register_paymethod_form");
	}
	 
	public ModelAndView payMethodList(HttpServletRequest request, HttpServletResponse response) throws Exception{
		 ArrayList list = pmDAO.selectAllPayMethod();
		 return new ModelAndView("select_all_paymethod", "list", list);
	}
	 
	public ModelAndView registerPayMethod(HttpServletRequest request, HttpServletResponse response, PayMethodVO pmvo) throws Exception{
		pmDAO.insertPayMethod(pmvo);
		ArrayList list = pmDAO.selectAllPayMethod();
		return new ModelAndView("select_all_paymethod", "list", list);
	}
	public ModelAndView updatePayMethodForm(HttpServletRequest request, HttpServletResponse response) throws Exception{
		 String code = request.getParameter("payMethodCode");
		 PayMethodVO pmvo = pmDAO.selectPayMethodByCode(code);
		 return new ModelAndView("update_paymethod_form", "pmvo", pmvo);
	 	}
	 public ModelAndView updatePayMethod(HttpServletRequest request, HttpServletResponse response, PayMethodVO pmvo) throws Exception{
			pmDAO.updatePayMethod(pmvo);
			ArrayList list = pmDAO.selectAllPayMethod();
			return new ModelAndView("select_all_paymethod", "list", list);
	 }
	 
	 public ModelAndView deleteByPayMethodCode(HttpServletRequest request, HttpServletResponse response) throws Exception{	
		 String code = request.getParameter("payMehtodCode");	
		 pmDAO.deletePayMethod(code);
		 	 ArrayList list = pmDAO.selectAllPayMethod();
			 return new ModelAndView("select_all_paymethod", "list", list);
	 }
	 
	 public ModelAndView selectByPayMethodCode(HttpServletRequest request, HttpServletResponse response) throws Exception{
		 String code = request.getParameter("payMehtodCode");
		 PayMethodVO pmvo = pmDAO.selectPayMethodByCode(code);
		 return new ModelAndView("update_location", "pmvo", pmvo);
	 }
}
